package com.iisigroup.project.statistics.typeI;

import java.io.File;
import java.io.IOException; 
import java.util.HashMap; 
import java.util.Map;

import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.transformer.XLSTransformer;

import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Workbook;
import org.robert.study.utils.POIUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import com.iisigroup.project.statistics.model.Func4Moi;
 
/**
 * The Class TypeIExporter.
 */
public class TypeIExporter {
    /** The Constant logger. */
    private static final Logger LOGGER = LoggerFactory.getLogger(TypeIExporter.class);
    
     
    public static void exportReport(final Func4Moi unit, final String fileName) throws  Exception{
        exportJxlsV2(unit, fileName);
    }
    
    /**
     * Export by jxls library.
     * 由於輸出資料不符合預期
     *
     * @param unit the unit
     * @param fileName the file name
     * @throws ParsePropertyException the parse property exception
     * @throws InvalidFormatException the invalid format exception
     * @throws IOException Signals that an I/O exception has occurred.
     * @deprecated
     */
    private static void exportJxlsV1(final Func4Moi unit, final String fileName) throws ParsePropertyException, InvalidFormatException, IOException {
        Map<String, Object> beans = new HashMap<String, Object>();
       
        beans.put("data", unit);
        XLSTransformer transformer = new XLSTransformer();
        final Workbook aHSSFWorkbook = transformer.transformXLS(TypeIExporter.class.getResource("RLFP_TEMPLATE.xls").openStream(), beans);
        POIUtils.writeWorkbookOut(new File(fileName), aHSSFWorkbook);
    }
    /**
     * Export by jxls library.
     * 由於輸出資料不符合預期
     *
     * @param unit the unit
     * @param fileName the file name
     * @throws ParsePropertyException the parse property exception
     * @throws InvalidFormatException the invalid format exception
     * @throws IOException Signals that an I/O exception has occurred.
     */
    private static void exportJxlsV2(final Func4Moi unit, final String fileName) throws ParsePropertyException, InvalidFormatException, IOException {
        Map<String, Object> beans = new HashMap<String, Object>();
       
        beans.put("data", unit);
        XLSTransformer transformer = new XLSTransformer();
        final Workbook aHSSFWorkbook = transformer.transformXLS(TypeIExporter.class.getResource("RLFP_TEMPLATE_v2.xls").openStream(), beans);
        POIUtils.writeWorkbookOut(new File(fileName), aHSSFWorkbook);
    }
   
}
